<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新闻添加</title>
<link rel="icon" href="${pageContext.request.contextPath}/favicon.ico"  type="image/x-icon"/>
<link href="${pageContext.request.contextPath}/style/news.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet">
<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<script src="${pageContext.request.contextPath}/bootstrap/js/jQuery.js"></script>
<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>
<script src="${pageContext.request.contextPath}/resources/scripts/jquery-1.3.2.min.js"></script>
<script src="${pageContext.request.contextPath}/resources/scripts/jquery.ocupload-1.1.2.js"></script>
<script type="text/javascript">
	function checkChange(){
		if(document.getElementById("isImage").checked){
			$("#hdtp").show();
		}else{
			$("#hdtp").hide();
		}
	}
	function checkForm(){
		var title=document.getElementById("title").value;
		var author=document.getElementById("author").value;
		var typeId=document.getElementById("typeId").value;
		var content=CKEDITOR.instances.content.getData();
		if(title==null||title==""){
			document.getElementById("error").innerHTML="新闻标题不能为空！";
			return false;
		}
		if(author==null||author==""){
			document.getElementById("error").innerHTML="作者不能为空！";
			return false;
		}
		if(typeId==null||typeId==""){
			document.getElementById("error").innerHTML="请选择新闻类别！";
			return false;
		}
		if(content==null||content==""){
			document.getElementById("error").innerHTML="新闻内容不能为空！";
			return false;
		}
		return true;
	}
</script>
</head>
<body>
<div class="data_list backMain">
	<div class="dataHeader navi">
		当前位置：&nbsp;&nbsp;
		主页&nbsp;&nbsp;&gt;&nbsp;&nbsp;
		新闻管理&nbsp;&nbsp;&gt;&nbsp;&nbsp;
		新闻添加&nbsp;&nbsp;
	</div>
	<div class="data_content">
		<form action="${pageContext.request.contextPath}/news" method="post"  onsubmit="return checkForm()">
			<input type="hidden" name="method" value="save" />
			<table cellpadding="5" width="100%">
				<tr>
					<td width="80px">
						<label>新闻标题：</label>
					</td>
					<td>
						<input type="text" id="title" name="title" class="input-xxlarge" value="${news.title}"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>新闻作者：</label>
					</td>
					<td>
						<input type="text" id="author" name="author" value="${news.author}"/>
					</td>
				</tr>
				<tr>
					<td>
						<label>新闻类别：</label>
					</td>
					<td>
						<select id="typeId" name="typeId">
							<option value="">请选择新闻类别</option>
							<c:forEach items="${types}" var="type">
								<option value="${type.id}">${type.typeName}</option>
							</c:forEach>
						</select>
					</td>
				</tr>
				<tr>
					<td>
						<label>新闻属性：</label>
					</td>
					<td>
						<label class="checkbox inline">
							<input type="checkbox" id="isHead" name="ishead" value="1" >头条
						</label>
						<label class="checkbox inline">
							<input type="checkbox" id="isImage" name="isimg" onclick="checkChange()" value="1" >幻灯
						</label>
						<label class="checkbox inline">
						  <input type="checkbox" id="isHot" name="ishot" value="1" >热点
						</label>
					</td>
				</tr>
				<tr id="hdtp" style="display: none">
					<td>
						<label>幻灯图片：</label>
					</td>
					<td>
						<a href="#" id="upload">上传</a>
						<img id="upload-img" style="width:200px;height:100px;display: none" src="" />
						<input type="hidden" id="imgUrl" name="imgUrl" value=""/>
					</td>
				</tr>
				<tr>
					<td valign="top">
						<label>新闻内容：</label>
					</td>
					<td>
						<textarea class="ckeditor" id="content" name="content"></textarea>
					</td>
				</tr>
				<tr>
					<td>
						<input type="hidden" id="newsId" name="id" value=""/>&nbsp;
					</td>
					<td>
						<input type="submit" class="btn btn-primary" value="保存新闻"/>&nbsp;&nbsp;
						<input type="button" class="btn btn-primary" value="返回" onclick="javascript:history.back()"/>&nbsp;
						&nbsp;<font id="error" color="red"></font>
					</td>
				</tr>
				
			</table>
		</form>
	</div>
</div>
</body>
<script>

	$("#upload").click(function(){
		$("#upload").upload({
			/* 上传路径  */
			 action: '${pageContext.request.contextPath }/imageUpload',
		     onComplete:function(data){
		    	if(data!=null && data!=""){
		    		$("#upload-img").attr("src",data);
		    		$("#upload-img").css("display","inline-block");
		    		$("input[name='imgUrl']").val(data);
		    	} else {
		    		alert("上传失败");
		    	}
		     }
		});
	});
</script>
</html>
